import java.util.Scanner;

/*
    缩位求和
 */
public class ContractionSummation {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        while (s.length() > 1){
            long num = 0;
            for (int i = 0 ; i < s.length() ; i++){
                num = num + s.charAt(i) - '0';
            }
            s = "" + num;
        }
        System.out.println(s);
    }
}
